//提交前:
#
include "flow.util";

var domainid = getDomainid();
var doc = getCurrentDocument();
var pDoc = getParentDocument();
var message = "";
var new_kf_str = doc.getItemValueAsString("xhtm_sjkf");
var new_xq_str = doc.getItemValueAsString("xhtm_xqfx");
var new_cs_str = doc.getItemValueAsString("xhtm_test");

if ((isNotNull(new_kf_str) && !isNumberText(new_kf_str)) || (isNotNull(new_xq_str) && !isNumberText(new_xq_str)) || (isNotNull(new_cs_str) && !isNumberText(new_cs_str))) {
    message = message + "工作量只能是数字类型";
} else {

    var new_kf = parseDouble((isNotNull(new_kf_str) ? new_kf_str : "0"));
    var new_xq = parseDouble((isNotNull(new_xq_str) ? new_xq_str : "0"));
    var new_cs = parseDouble((isNotNull(new_cs_str) ? new_cs_str : "0"));

    var sql_1 = "select '" + domainid + "'  as domainid, item_xhtm_sjkf as item_kf, item_xhtm_xqfx as item_xq, item_xhtm_test as item_cs from tlk_clause_thin where id = '" + doc.getId() + "'";
    var result_1 = findBySQL(sql_1);
    var old_kf = result_1.getItemValueAsDouble("kf");
    var old_xq = result_1.getItemValueAsDouble("xq");
    var old_cs = result_1.getItemValueAsDouble("cs");



    var diff_kf = 0;
    var diff_xq = 0;
    var diff_cs = 0;

    if (new_kf > old_kf || new_kf == old_kf) {
        diff_kf = new_kf - old_kf;
        diff_kf = "+" + diff_kf;
    } else {
        diff_kf = old_kf - new_kf;
        diff_kf = "-" + diff_kf;
    }


    if (new_xq > old_xq || new_xq == old_xq) {
        diff_xq = new_xq - old_xq;
        diff_xq = "+" + diff_xq;
    } else {
        diff_xq = old_xq - new_xq;
        diff_xq = "-" + diff_xq;
    }

    if (new_cs > old_cs || new_cs == old_cs) {
        diff_cs = new_cs - old_cs;
        diff_cs = "+" + diff_cs;
    } else {
        diff_cs = old_cs - new_cs;
        diff_cs = "-" + diff_cs;
    }




    var old_num = old_kf + old_xq + old_cs;
    var new_num = new_kf + new_xq + new_cs;

    var diff = 0;

    if (new_num > old_num || new_num == old_num) {
        diff = new_num - old_num;
        diff = "+" + diff;
    } else {
        diff = old_num - new_num;
        diff = "-" + diff;
    }

    var type = pDoc.getItemValueAsString("ztkfs");

    var prefix = "";
    if ("中汇公司".equals(type)) {
        prefix = "zhgs";
    } else if ("外包公司".equals(type)) {
        prefix = "wbgs";
    }

    var sql_2 = "update tlk_workload_assess_info set item_" + prefix + "_xqfxgzl = item_" + prefix + "_xqfxgzl" + diff_xq +
        ", item_" + prefix + "_sjkfgzl=item_" + prefix + "_sjkfgzl" + diff_kf +
        ", item_" + prefix + "_uiitcs=item_" + prefix + "_uiitcs" + diff_cs +
        " where id = '" + pDoc.getId() + "'";
    updateByDSName(datasource, sql_2);

    type = pDoc.getItemValueAsString("ztkfs");
    if ("中汇公司".equals(type)) {
        prefix = "zh";
    } else if ("外包公司".equals(type)) {
        prefix = "wb";
    }
    var sql_3 = "update tlk_workload_assess_info set item_" + prefix + "gzl_zj = item_" + prefix + "gzl_zj" + diff + ", item_gzlzj=item_gzlzj" + diff +
        ", item_" + prefix + "gzl_zs=(item_" + prefix + "gzl_zj)/20.83" +
        ", item_gzl_zs=(item_gzlzj)/20.83 where id = '" + pDoc.getId() + "'";
    updateByDSName(datasource, sql_3);
    println("进入了正确的分支逻辑");
}
println("提示信息：" + message);
message;